#include"Sem_V1.hpp"

int main()
{
    SemaphoreBuilder sb;
    auto fsem = sb.SetVal(1).Build(BUILD_SEM,10); // 创建信号量集合,只有⼀个信号量，初始化成为1,就是当做锁来进⾏使⽤
    srand(time(0) ^ getpid());
    if (fork() == 0)
    {
        auto csem = sb.Build(GET_SEM);
        while (true)
        {
            csem->P();
            printf("C");
            fflush(stdout);
            usleep(rand() % 95270);
            printf("C ");
            usleep(rand() % 43990);
            fflush(stdout);
            csem->V();
        }
    }

        
    while (true)
    {
        fsem->P();
        printf("F");
        fflush(stdout);
        usleep(rand() % 95270);
        printf("F ");
        usleep(rand() % 43990);
        fflush(stdout);
        fsem->V();
    }
    return 0;
}